var map;
//基本地图加载
function initMap(center) {
    map = new AMap.Map('container', {
        viewMode: '2D', // 默认使用 2D 模式，如果希望使用带有俯仰角的 3D 模式，请设置 viewMode: '3D'
        zoom: 10, // 初始化地图层级
        center:  center.split(",")// 初始化地图中心点
    });
}
//起始点，结束点，交通方式(骑行，步行，驾车，公交地铁)，城市?
function NaviBy(arr){
    initMap(arr[0])
    //构造路线导航类
    let point1 = arr[0].split(",");
    let point2 = arr[1].split(",");
    let drive = arr[2];
    let city = (arr.length > 3 ? arr[3] : "");
    map.setCenter(point1)

    var transOptions = {
        map: map,
        panel: "panel",
        city: city
    };
    var driving;
    if(drive == "公交地铁"){
        driving = new AMap.Transfer(transOptions);
    }else if(drive == "驾车"){
        driving = new AMap.Driving(transOptions);
    }else if(drive == "骑行"){
        driving = new AMap.Riding(transOptions);
    }else if(drive == "步行"){
        driving = new AMap.Walking(transOptions);
    }
    // 根据起终点名称规划导航路线
    driving.search(
        new AMap.LngLat(point1[0], point1[1]),
        new AMap.LngLat(point2[0], point2[1]),
        function(status, result) {
            // result 即是对应的驾车导航信息，相关数据结构文档请参考  https://lbs.amap.com/api/javascript-api/reference/route-search#m_DrivingResult
            if (status === 'complete') {
                log.success('绘制驾车路线完成')
            } else {
                log.error('获取驾车数据失败：' + result)
            }
        });
}

